using System;
using System.Collections.Generic;
using System.Text;

using Deepcode.Flux.Core.Extensions;

namespace Deepcode.Flux.Core.Systems.Workflow.Bases
{
	/// <summary>
	/// Management class for known workflow handlers
	/// </summary>
	public class Handlers
	{
		/// <summary>
		/// Returns a list of all workflow handlers known on the system
		/// </summary>
		/// <returns></returns>
		public Handler[] GetAllHandlers()
		{
			AddinTreeNode qmRoot = AddinTree.Tree.GetTreeNodeNoThrow("/Flux/Workflow/Handlers/");
			if (qmRoot != null)
				return qmRoot.BuildChildItems( this ).ToArray( typeof( Handler )) as Handler [];

			List<Handler> l = new List<Handler>();
			return l.ToArray();
		}
		/// <summary>
		/// Returns a specific handler by it's ID
		/// </summary>
		/// <param name="HandlerCodeID"></param>
		/// <returns></returns>
		public Handler GetHandlerByID(string HandlerCodeID)
		{
			AddinTreeNode qmRoot = AddinTree.Tree.GetTreeNodeNoThrow("/Flux/Workflow/Handlers/");
			if( qmRoot != null )
				return qmRoot.BuildChildItem( HandlerCodeID, this ) as Handler;

			return null;
		}
	}
}
